home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / cips3.c < prev    next >
C/C++ Source or Header  |  1993-06-29  |  14KB  |  499 lines

  1.  
  2.    /*************************** 
  3.    * 
  4.    *   cips3.c 
  5.    *   COMPOSITE FILE COMPRISING: 
  6.    *   addsub.c 
  7.    *   cutp.c 
  8.    *   rotate.c 
  9.    * 
  10.    ***************************\ 
  11.  
  12.  
  13.  
  14.  
  15.    /***********************************************
  16.    *
  17.    *       file d:\cips\addsub.c
  18.    *
  19.    *       Functions: This file contains
  20.    *          add_image_array
  21.    *          subtract_image_array
  22.    *
  23.    *       Purpose:
  24.    *          These functions implement
  25.    *          image addition and subtraction.
  26.    *
  27.    *       External Calls:
  28.    *          wtiff.c - round_off_image_size
  29.    *                    create_file_if_needed
  30.    *                    write_array_into_tiff_image
  31.    *          tiff.c - read_tiff_header
  32.    *          rtiff.c - read_tiff_image
  33.    *
  34.    *
  35.    *       Modifications:
  36.    *          1 April 1992 - created
  37.    *
  38.    *************************************************/
  39.  
  40. #include "cips.h"
  41.  
  42.      /*******************************************
  43.      *
  44.      *   add_image_array(...
  45.      *
  46.      *   This function adds two ROWSxCOLS image
  47.      *   sections.  The image file named out_name
  48.      *   will receive the sum of the image file
  49.      *   named in1_name and the image file
  50.      *   named in2_name.
  51.      *
  52.      *******************************************/
  53.  
  54.  
  55. add_image_array(in1_name, in2_name, out_name, 
  56.                 the_image, out_image,
  57.           il1, ie1, ll1, le1,
  58.           il2, ie2, ll2, le2,
  59.           il3, ie3, ll3, le3)
  60.    char   in1_name[], in2_name[], out_name[];
  61.    int    il1, ie1, ll1, le1,
  62.           il2, ie2, ll2, le2,
  63.           il3, ie3, ll3, le3;
  64.    short  the_image[ROWS][COLS],
  65.           out_image[ROWS][COLS];
  66.  
  67. {
  68.    int    i, j, length, max, width;
  69.    struct tiff_header_struct image_header;
  70.  
  71.    create_file_if_needed(in1_name, out_name, out_image);
  72.  
  73.    read_tiff_header(in1_name, &image_header);
  74.  
  75.    max = 255;
  76.    if(image_header.bits_per_pixel == 4)
  77.       max = 16;
  78.  
  79.    read_tiff_image(in1_name, the_image, 
  80.                    il1, ie1, ll1, le1);
  81.    read_tiff_image(in2_name, out_image, 
  82.                    il2, ie2, ll2, le2);
  83.  
  84.    for(i=0; i<ROWS; i++){
  85.       for(j=0; j<COLS; j++){
  86.          out_image[i][j] = the_image[i][j] + 
  87.                            out_image[i][j];
  88.          if(out_image[i][j] > max)
  89.             out_image[i][j] = max;
  90.       }  /* ends loop over j */
  91.    }  /* ends loop over i */
  92.  
  93.    write_array_into_tiff_image(out_name, out_image,
  94.                                il3, ie3, ll3, le3);
  95.  
  96. }  /* ends add_image_array */
  97.  
  98.  
  99.  
  100.  
  101.  
  102.      /*******************************************
  103.      *
  104.      *   subtract_image_array(...
  105.      *
  106.      *   This function subtracts two ROWSxCOLS image
  107.      *   sections.  The image file named out_name
  108.      *   will receive the difference of the image file
  109.      *   named in1_name and the image file
  110.      *   named in2_name.
  111.      *
  112.      *   out_name = in1_name - in2_name
  113.      *
  114.      *******************************************/
  115.  
  116.  
  117. subtract_image_array(in1_name, in2_name, out_name, 
  118.                      the_image, out_image,
  119.           il1, ie1, ll1, le1,
  120.           il2, ie2, ll2, le2,
  121.           il3, ie3, ll3, le3)
  122.    char   in1_name[], in2_name[], out_name[];
  123.    int    il1, ie1, ll1, le1,
  124.           il2, ie2, ll2, le2,
  125.           il3, ie3, ll3, le3;
  126.    short  the_image[ROWS][COLS],
  127.           out_image[ROWS][COLS];
  128.  
  129. {
  130.    int    i, j, length, width;
  131.    struct tiff_header_struct image_header;
  132.  
  133.  
  134.    create_file_if_needed(in1_name, out_name, out_image);
  135.  
  136.    read_tiff_header(in1_name, &image_header);
  137.  
  138.    read_tiff_image(in1_name, the_image, 
  139.                    il1, ie1, ll1, le1);
  140.    read_tiff_image(in2_name, out_image, 
  141.                    il2, ie2, ll2, le2);
  142.  
  143.    for(i=0; i<ROWS; i++){
  144.       for(j=0; j<COLS; j++){
  145.          out_image[i][j] = the_image[i][j] - 
  146.                            out_image[i][j];
  147.          if(out_image[i][j] < 0)
  148.             out_image[i][j] = 0;
  149.       }  /* ends loop over j */
  150.    }  /* ends loop over i */
  151.  
  152.    write_array_into_tiff_image(out_name, out_image,
  153.                                il3, ie3, ll3, le3);
  154.  
  155. }  /* ends subtract_image_array */
  156.  
  157.     /***********************************************
  158.     *
  159.     *       file d:\cips\cutp.c
  160.     *
  161.     *       Functions: This file contains
  162.     *          cut_image_piece
  163.     *          paste_image_piece
  164.     *          check_cut_and_paste_limits
  165.     *
  166.     *       Purpose:
  167.     *          These functions cut pieces out
  168.     *          of images and paste them back into
  169.     *          images.
  170.     *
  171.     *       External Calls:
  172.     *          wtiff.c - does_not_exist
  173.     *                    round_off_image_size
  174.     *                    create_file_if_needed
  175.     *                    write_array_into_tiff_image
  176.     *          tiff.c - read_tiff_header
  177.     *          rtiff.c - read_tiff_image
  178.     *
  179.     *
  180.     *       Modifications:
  181.     *          3 April 1992 - created
  182.     *
  183.     *************************************************/
  184.  
  185.  
  186.      /*******************************************
  187.      *
  188.      *   cut_image_piece(...
  189.      *
  190.      *   This function cuts out a rectangular
  191.      *   piece of an image.  This rectangle can
  192.      *   be any shape so long as no dimension
  193.      *   is greater than ROWS or COLS.
  194.      *
  195.      *******************************************/
  196.  
  197.  
  198. cut_image_piece(name, the_image, il, ie, ll, le)
  199.    char   name[];
  200.    int    il, ie, ll, le;
  201.    short  the_image[ROWS][COLS];
  202.  
  203. {
  204.    if(does_not_exist(name)){
  205.       printf("\n\ncut_image_piece>> ERROR "
  206.              "image file does not exist %s", name);
  207.       return(-1);
  208.    }  /* ends if does_not_exist */
  209.  
  210.    read_tiff_image(name, the_image, il, ie, ll, le);
  211.  
  212. }  /* ends cut_image_piece */
  213.  
  214.  
  215.  
  216.  
  217.      /*******************************************
  218.      *
  219.      *   paste_image_piece(...
  220.      *
  221.      *   This function pastes a rectangular
  222.      *   piece of an image into another image.
  223.      *   This rectangle can be any shape so long
  224.      *   as no dimension is greater than ROWS or COLS.
  225.      *   The rectangle to be pasted into the image
  226.      *   is described by the il, ie, ll, le
  227.      *   parameters.
  228.      *
  229.      *   You pass is the out_image array just in
  230.      *   case you need to allocate the destination
  231.      *   image.
  232.      *
  233.      *******************************************/
  234.  
  235.  
  236. paste_image_piece(dest_name, source_name, the_image,
  237.                   out_image, il, ie, ll, le)
  238.    char   dest_name[], source_name[];
  239.    int    il, ie, ll, le;
  240.    short  the_image[ROWS][COLS],
  241.           out_image[ROWS][COLS];
  242.  
  243. {
  244.    struct tiff_header_struct image_header;
  245.  
  246.    create_file_if_needed(source_name, dest_name, 
  247.                          out_image);
  248.  
  249.    write_array_into_tiff_image(dest_name, the_image,
  250.                                il, ie, ll, le);
  251.  
  252. }  /* ends paste_image_piece */
  253.  
  254.  
  255.  
  256.      /*******************************************
  257.      *
  258.      *   check_cut_and_paste_limits(...
  259.      *
  260.      *   This function looks at the line and
  261.      *   element parameters and ensures that they
  262.      *   are not bigger than ROWS and COLS.  If
  263.      *   they are bigger, the last element or
  264.      *   last line parameters are reduced.
  265.      *
  266.      *******************************************/
  267.  
  268. check_cut_and_paste_limits(il, ie, ll, le)
  269.    int *il, *ie, *ll, *le;
  270. {
  271.    if((*ll - *il) > ROWS)
  272.       *ll = *il + ROWS;
  273.    if((*le - *ie) > COLS)
  274.       *le = *ie + COLS;
  275. }  /* ends check_cut_and_paste_limits */
  276.  
  277.  
  278.     /***********************************************
  279.     *
  280.     *       file d:\cips\rotate.c
  281.     *
  282.     *       Functions: This file contains
  283.     *          rotate_flip_image_array
  284.     *
  285.     *       Purpose:
  286.     *          This function rotates or flips an image
  287.     *          array in one of five ways.
  288.     *
  289.     *       External Calls:
  290.     *          wtiff.c - round_off_image_size
  291.     *                    create_file_if_needed
  292.     *                    write_array_into_tiff_image
  293.     *          tiff.c - read_tiff_header
  294.     *          rtiff.c - read_tiff_image
  295.     *
  296.     *